package com.cskaoyan.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

//@Component
public class CustomWebSessionManager extends DefaultWebSessionManager {
    private static final String ADMIN_TOKEN = "X-CskaoyanMarket-Admin-Token";
    private static final String WX_TOKEN = "X-CskaoyanMarket-Token";


    @Override
    protected Serializable getSessionId(ServletRequest servletRequest, ServletResponse servletResponse) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String sessionId = request.getHeader(ADMIN_TOKEN);
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        String sessionId2 = request.getHeader(WX_TOKEN);
        if (sessionId2 != null && !"".equals(sessionId2)) {
            return sessionId2;
        }
        return super.getSessionId(request, servletResponse);
    }
}
